package cn.stronglink.assetmanage.business.inspection.view.repairDetail;

import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.check.model.CheckDetailModel;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.RepailDetail;
import cn.stronglink.assetmanage.entity.SearchAsset;
import cn.stronglink.assetmanage.entity.Type;
import cn.stronglink.assetmanage.entity.User;
import cn.stronglink.assetmanage.utils.ToastUtil;

/**
 * 维修详情页面
 * Created by zhengjinglan on 2018/6/15.
 */

public class RepairDetailView {
    @BindView(R.id.et_repair_detail_assis_name)
    TextView et_repair_detail_assis_name;
    @BindView(R.id.et_repair_detail_assis_sn)
    TextView et_repair_detail_assis_sn;
    @BindView(R.id.et_repair_detail_rfid)
    TextView et_repair_detail_rfid;
    @BindView(R.id.tv_repair_detail_assis_type)
    TextView tv_repair_detail_assis_type;
    @BindView(R.id.et_repair_detail_note)
    EditText et_repair_detail_note;
    RepailDetail repailDetail;
    @BindView(R.id.tv_repair_detail_date)
    TextView tv_repair_detail_date;
    @BindView(R.id.tv_repair_detail_people)
    TextView tv_repair_detail_people;
    private Fragment fragment;

    public RepairDetailView(Fragment fragment, View view) {
        this.fragment = fragment;
        ButterKnife.bind(this, view);
    }

    /**
     * 设置显示信息
     *
     * @param repailDetail
     */
    public void showDetail(RepailDetail repailDetail) {
//        if (asset != null && repailDetail != null && brandIndex != -1) {
//            this.repailDetail = repailDetail;
//            et_repair_detail_assis_name.setText(asset.getAssetName());
//            et_repair_detail_assis_sn.setText(asset.getSerialNo());
//            et_repair_detail_rfid.setText(asset.getRfidNo());
//            tv_repair_detail_assis_type.setText(asset.getTypeName());
//        } else {
//            this.repailDetail = new RepailDetail();
//        }

        et_repair_detail_assis_name.setText(repailDetail.getAssetName());
        et_repair_detail_assis_sn.setText(repailDetail.getSerialNo());
        et_repair_detail_rfid.setText(repailDetail.getRfidNo());
        tv_repair_detail_assis_type.setText(repailDetail.getTypeName());
    }


    public RepailDetail saveRepailDetail(RepailDetail repailDetails) {
        repailDetail = repailDetails;
        repailDetail.setExecuteTime(tv_repair_detail_date.getText().toString());
        repailDetail.setRemark(et_repair_detail_note.getText().toString());
        repailDetail.setAssetName(et_repair_detail_assis_name.getText().toString());
        repailDetail.setSerialNo(et_repair_detail_assis_sn.getText().toString());
        repailDetail.setRfidNo(et_repair_detail_rfid.getText().toString());
        repailDetail.setTypeName(tv_repair_detail_assis_type.getText().toString());
        String userName = tv_repair_detail_people.getText().toString();
        CheckDetailModel checkDetailModel = new CheckDetailModel();
        long userId = checkDetailModel.getUserIndex(userName);
        repailDetail.setOperatorBy(userId);
        return repailDetail;
    }

    public void showProgressDialog(String msg) {

    }

    public void hideProgressDialog() {

    }

    public void showToast(String msg) {
        ToastUtil.toastShort(msg);
    }

    public void setRepairDate(String opeateDate) {
        repailDetail.setExecuteTime(opeateDate);
    }
}
